home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / edit / tecoc-146.lha / exeq.c < prev    next >
C/C++ Source or Header  |  1991-07-05  |  3KB  |  89 lines

  1. /*****************************************************************************
  2.  
  3.     ExeQ()
  4.  
  5.     This function executes a Q command.
  6.  
  7.     Qq    Use the integer stored in the number storage area of
  8.         Q-register q as the argument of the next command.
  9.  
  10.     nQq    Return the ASCII value of the (n+1)th character in
  11.         Q-register q.  The argument n must be between 0 and the
  12.         Q-register's size minus 1.  If n is out of range, a
  13.         value of -1 is returned.  Characters within a
  14.         Q-register are numbered the same way that characters in
  15.         the text buffer are numbered.  The initial character is
  16.         at character position 0, the next character is at
  17.         character position 1, etc.  Therefore, if Q-register A
  18.         contains "xyz", then 0QA will return the ASCII code for
  19.         "x" and 1QA will return the ASCII code for "y".
  20.  
  21.     :Qq    Return the number of characters stored in the text storage
  22.         area of Q-register q as the argument of the next command.
  23.  
  24. *****************************************************************************/
  25.  
  26. #include "zport.h"        /* define portability identifiers */
  27. #include "tecoc.h"        /* define general identifiers */
  28. #include "defext.h"        /* define external global variables */
  29. #include "deferr.h"        /* define identifiers for error messages */
  30.  
  31. DEFAULT ExeQ()            /* execute a Q command */
  32. {
  33.     LONG    TmpVal;
  34.  
  35.     DBGFEN(1,"ExeQ",NULL);
  36.  
  37. /*
  38.  * increment command buffer pointer to point to Q-register name
  39.  */
  40.  
  41.     if (IncCBP() == FAILURE) {
  42.         DBGFEX(1,DbgFNm,"FAILURE, no Q-register specified");
  43.         return FAILURE;
  44.     }
  45.  
  46. /*
  47.  * verify Q-register name and point QR global at it
  48.  */
  49.  
  50.     if (FindQR() == FAILURE) {
  51.         DBGFEX(1,DbgFNm,"FAILURE, FindQR() failed");
  52.         return FAILURE;
  53.     }
  54.  
  55. /*
  56.  * if something is on the stack and it's a number then we have nQq
  57.  */
  58.  
  59.     if ((EStTop > EStBot) && (EStack[EStTop].ElType == OPERAND)) {
  60.         if (GetNmA() == FAILURE) {    /* get numeric argument */
  61.             DBGFEX(1,DbgFNm,"FAILURE, GetNmA() failed");
  62.             return FAILURE;
  63.         }
  64.  
  65. /*
  66.  * if NArgmt is between 0 and length of text area, return the ASCII value
  67.  * of the (NArgmt+1)th character, otherwise return -1
  68.  */
  69.  
  70.         TmpVal = (NArgmt >= 0 && NArgmt < (QR->End_P1 - QR->Start))
  71.                 ? *(QR->Start + NArgmt)
  72.                 : -1;
  73.         EStTop = EStBot;        /* clear expression stack */
  74.     } else {                /* else we have Qq or :Qa */
  75.         if (CmdMod & COLON) {        /* if it's :Qa */
  76.             TmpVal = QR->End_P1 - QR->Start;
  77.             CmdMod &= ~COLON;    /* clear colon flag */
  78.         } else {
  79.             TmpVal = QR->Number;
  80.         }
  81.     }
  82. #if DEBUGGING
  83.     sprintf(DbgSBf,"PushEx(%ld,OPERAND)",TmpVal);
  84.     DbgFEx(1,DbgFNm,DbgSBf);
  85. #endif
  86.  
  87.     return PushEx(TmpVal,OPERAND);
  88. }
  89.